//公共js 自适应+日期格式化
class Base {
    constructor(option) {
        this.userId = option.userId
        this.key = option.key
    }
    empty(obj) {
        for (let key in obj) {
            return false;    //非空
        }
        return true;
    }
}
(function (win, doc) {
    var fres = function () {
        var html = doc.documentElement;   
        var w = html.clientWidth;
        w && (html.style.fontSize = 10 * (w / 375) + "px"); //显示器31.9467 本机44.7467// fontsize设置成1/100大
    }
    if (document.readyState === 'complete') {
        fres();
    } else {
        document.addEventListener('DOMContentLoaded', fres, false);
    }
    window.addEventListener('resize', fres, false);
})(window, document) //自适应 √
Date.prototype.Format = function (fmt) {
    var o = {
        "M+": this.getMonth() + 1, //月份
        "d+": this.getDate(), //日
        "h+": this.getHours(), //小时
        "m+": this.getMinutes(), //分
        "s+": this.getSeconds(), //秒
        "q+": Math.floor((this.getMonth() + 3) / 3), //季度
        "S": this.getMilliseconds() //毫秒
    };
    if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
    for (var k in o)
        if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[
            k]) : (("00" + o[k]).substr(("" + o[k]).length)));
    return fmt;
} //日期格式化 √
//js封装监听事件
var Evt = {
    callback: [],
    sendEvent: function (key, value) {
        var uuid = this.uuid(8, 16);
        localStorage.setItem('evt_' + key, uuid + '_' + value);
      
    },
    addEvent: function (key, callback) {
        if (this.callback.length > 0) {
            var b = false;
            for (var i in this.callback) {
                var item = this.callback[i];
                if (item.key == key) {
                    this.callback[i].callback = callback;
                    b = true;
                }
            }
            if (!b) {
                var data = { key: key, callback: callback };
                this.callback.push(data);
            }
        } else {
            var data = { key: key, callback: callback };
            this.callback.push(data);
        }

    },

    uuid: function (len, radix) {
        var chars = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'.split('');
        var uuid = [], i;
        radix = radix || chars.length;
        if (len) {
            for (i = 0; i < len; i++) uuid[i] = chars[0 | Math.random() * radix];
        } else {
            var r;
            uuid[8] = uuid[13] = uuid[18] = uuid[23] = '-';
            uuid[14] = '4';
            for (i = 0; i < 36; i++) {
                if (!uuid[i]) {
                    r = 0 | Math.random() * 16;
                    uuid[i] = chars[(i == 19) ? (r & 0x3) | 0x8 : r];
                }
            }
        }

        return uuid.join('');
    }
};
window.addEventListener("storage", function (event) {
    if (event.key.indexOf('evt_') < 0) return;
    var key = event.key.split('_');
    if (Evt.callback.length > 0) {
        for (var j in Evt.callback) {
            if (key[1] == Evt.callback[j].key) {
                var start = event.newValue.indexOf('_') + 1;
                var end = event.newValue.length;
                var value = event.newValue.substring(start, end);
                Evt.callback[j].callback(Evt.callback[j].key, value);
                break;
            }
        }
    }
});
//闪烁
function light(id) {
    $(id).css('background', 'red');  //默认值
    setTimeout(function () {
        $(id).css('background', '#fff');
    }, 1000); //第一次闪烁
    setTimeout(function () {
        $(id).css('background', 'red');
    }, 2000);

    setTimeout(function () {
        $(id).css('background', '#fff');
    }, 3000);
    setTimeout(function () {
        $(id).css('background', 'red');
    }, 4000);
    setTimeout(function () {
        $(id).css('background', '#fff');
    }, 5000);

    setTimeout(function () {
        $(id).css('background', 'red');
    }, 6000);
    setTimeout(function () {
        $(id).css('background', '#fff');
    }, 7000);

    setTimeout(function () {
        $(id).css('background', 'red');
    }, 8000);
    setTimeout(function () {
        $(id).css('background', '#fff');
    }, 9000);
}

